import { createRouter, createWebHistory } from 'vue-router'


const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "about" */ '../views/Login'), //登录,
  },
  {
    path: '/home',
    component: () => import(/* webpackChunkName: "about" */ '../views/Home'), //首页
    meta: {
      isFinite: true
    }
  },
  {
    path: '/newhouse',
    component: () => import(/* webpackChunkName: "about" */ '../views/Newhouse'), //新房
    meta: {
      isFinite: true
    }
  },
  {
    path: '/secondhouse',
    component: () => import(/* webpackChunkName: "about" */ '../views/Secondhouse'), //二手房
    meta: {
      isFinite: true
    }
  },
  {
    path: '/rentalhouse',
    component: () => import(/* webpackChunkName: "about" */ '../views/Rentalhouse'), //出租房
    meta: {
      isFinite: true
    }
  },
  {
    path: '/message',
    component: () => import(/* webpackChunkName: "about" */ '../views/Message'), //消息列表
    meta: {
      isFinite: true
    }
  },
  {
    path: '/begRent',
    component: () => import(/* webpackChunkName: "about" */ '../views/BegRent'), //求租
    meta: {
      isFinite: true
    }
  },
  {
    path: '/askbuy',
    component: () => import(/* webpackChunkName: "about" */ '../views/Askbuy'), //求购
    meta: {
      isFinite: true
    }
  },
  {
    path: '/realmarket',
    component: () => import(/* webpackChunkName: "about" */ '../views/Realmarket'), //楼市圈
    meta: {
      isFinite: true
    }
  },
  {
    path: '/issue',
    component: () => import(/* webpackChunkName: "about" */ '../views/Issue'), //发布
    meta: {
      isFinite: true
    }
  },
  {
    path: '/live',
    component: () => import(/* webpackChunkName: "about" */ '../views/Live'), //直播
    meta: {
      isFinite: true
    }
  },
  {
    path: '/newLive',
    component: () => import(/* webpackChunkName: "about" */ '../views/NewLive'), //创建直播
    meta: {
      isFinite: true
    }
  },
  {
    path: '/group',
    component: () => import(/* webpackChunkName: "about" */ '../views/Group'), //团购
    meta: {
      isFinite: true
    }
  },
  {
    path: '/newgroup',
    component: () => import(/* webpackChunkName: "about" */ '../views/Newgroup'), //新建团购
    meta: {
      isFinite: true
    }
  },
  {
    path: '/Startgroup',
    component: () => import(/* webpackChunkName: "about" */ '../views/Startgroup'),//开团
    meta: {
      isFinite: true
    }
  },
  {
    path: '/groupdetail',
    component: () => import(/* webpackChunkName: "about" */ '../views/Groupdetail'), //团购详情
    meta: {
      isFinite: true
    }
  },
  {
    path: '/ranklist',
    component: () => import(/* webpackChunkName: "about" */ '../views/Ranklist'), //排行榜
    meta: {
      isFinite: true
    }
  },
  {
    path: '/maifang',
    component: () => import(/* webpackChunkName: "about" */ '../views/Maifang'), //卖房
    meta: {
      isFinite: true
    }
  },
  {
    path: '/zufang',
    component: () => import(/* webpackChunkName: "about" */ '../views/Zufang'), //租房
    meta: {
      isFinite: true
    }
  },
  {
    path: '/good',
    component: () => import(/* webpackChunkName: "about" */ '../views/Good'), //城市
    meta: {
      isFinite: true
    }
  },
  {
    path: '/context',
    component: () => import(/* webpackChunkName: "about" */ '../views/Context'), //求租电话
    meta: {
      isFinite: true
    }
  },
  {
    path: '/response',
    component: () => import(/* webpackChunkName: "about" */ '../views/Response'), //
    meta: {
      isFinite: true
    }
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach(function (to, from, next) {
  if (to.meta.isFinite) {
    if (sessionStorage.getItem('token')) {
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
})

export default router
